package com.jfl.aspect;

import org.apache.shiro.authz.UnauthorizedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 控制器异常通知
 * 
 * @author 赵炎
 * @version [V1.00, 2018年12月12日]
 * @since V1.00
 */
@ControllerAdvice
public class BusinsessExceptionHandler
{
    private static final Logger LOG = LoggerFactory.getLogger(BusinsessExceptionHandler.class);
    
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ModelMap execeptionHandler(Exception ex)
    {
        LOG.error("请求出现了异常", ex);
        String message = "";
        if(ex instanceof UnauthorizedException)
        {
            message = "该用户没有此操作权限，请授权后操作！";
        }
        else 
        {
            message = ex.getMessage();
        }
        ModelMap modelMap = new ModelMap();
        modelMap.put("message", message);
        modelMap.put("success", Boolean.FALSE);
        modelMap.put("timestamp", System.currentTimeMillis()); 
        return modelMap;
    }
}
